package com.jackeysun.common.text

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import com.jackeysun.common.databinding.LayoutOperateWindowsBinding

/**
 *   Created by sunxunchao on 2022/1/4.
 */
open class SimplePopupWindow(val context: Context) : AbsPopupWindow(context) {

    val TAG: String = SimplePopupWindow::class.java.simpleName

    lateinit var mBinding: LayoutOperateWindowsBinding
    override fun onCreateView(context: Context): View {
        mBinding = LayoutOperateWindowsBinding.inflate(LayoutInflater.from(context))
        return mBinding.root
    }

    override fun onViewCreated(contentView: View) {
        elevation = 8f
        isFocusable = true
        isClippingEnabled = false
        isOutsideTouchable = true
    }

    override fun showAtLocation(anchor: IViewProtocol, gravity: Int, x: Int, y: Int) {
        Log.d(TAG, "showAtLocation: ${width}, ${height}")
        super.showAtLocation(anchor, gravity, x, y)
        Log.d(TAG, "showAtLocation: ${anchor.getSelectedText()}")
        mBinding.tvContent.text = "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
        mBinding.tvContent.post {
            Log.d(TAG, "showAtLocation: ${width}, ${mBinding.tvContent.measuredHeight}, ${mBinding.scrollView.measuredHeight}")
            super.update(width,mBinding.tvContent.measuredHeight)
        }
    }

    override fun update(anchor: View?, width: Int, height: Int) {
        super.update(anchor, width, height)
    }
}